package logic.blocks;

import logic.characters.Player;
import logic.enemies.Enemy;
import logic.enemies.Paratroopa;
import logic.pruebas.GamePanel;

/**
 * @author Unai
 * Bloque de hielo, duplica la velocidad
 */
public class Ice extends Block{
	private static final long serialVersionUID = 5854734503972665613L;

	/**
	 * @param x
	 * @param y
	 * @param panel
	 * @param nomImg
	 * @param player
	 */
	public Ice(float x, float y, GamePanel panel, String nomImg, Player player) {
		super(x, y, panel, nomImg, player);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void upImpact(Player player) {
		player.falling = true;
		player.velY = 0;
		player.coorY = coorY + altura + 1 - player.heightDifference;				
	}

	@Override
	public void downImpact(Player player) {
		if (!player.attacking && !player.throwing && !player.special) {
			player.falling = false;
			playerOnThis = true;
			player.onPlatform = true;
			player.jumping= false;
			if (player.lookingRight) {
				if (player.movingRight) {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/RR.gif");
				} else if (!player.attacking) {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/IR.gif");
				}
			} else {
				if (player.movingLeft) {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/RL.gif");
				} else {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/IL.gif");
				}
			}
		}
		
		player.velY = 0;
		player.coorY = coorY - player.altura - 1;
		
		player.speed = player.speed * 2;
	}

	@Override
	public void leftImpact(Player player) {
		player.velX = 0;
		player.coorX = coorX + anchura + 1 - (player.collisionX - player.coorX);
				
	}

	@Override
	public void rightImpact(Player player) {
		player.velX = 0;
		player.coorX = coorX - player.anchura - 1 + ((player.coorX + player.anchura) - (player.collisionX + player.collisionWidth));
				
	}

	@Override
	public void upImpact(Enemy enemy) {
		enemy.falling = true;
		enemy.velY = 0;
		enemy.coorY = coorY + altura + 1 - (enemy.altura - enemy.collisionHeight);
		
	}

	@Override
	public void downImpact(Enemy enemy) {
		enemy.falling = false;
		enemy.onPlatform = true;
		enemyOnThis = true;
		enemy.velY = 0;
		enemy.coorY = coorY - enemy.altura - 1;
		if (enemy instanceof Paratroopa) {
			Paratroopa paratroopa = (Paratroopa) enemy;
			paratroopa.jump();
		}
		
		enemy.speed = enemy.speed * 2;
	}

	@Override
	public void leftImpact(Enemy enemy) {
		enemy.coorX = coorX + anchura + 1 - (enemy.collisionX - enemy.coorX);
		enemy.velX = -enemy.velX;		
	}

	@Override
	public void rightImpact(Enemy enemy) {
		enemy.coorX = coorX - enemy.anchura - 1;
		enemy.velX = -enemy.velX;		
	}
	
	public void endCollision(Player player) {
		super.endCollision(player);
		player.speed = player.originalSpeed;
	}
	
	public void endCollision(Enemy enemy) {
		super.endCollision(enemy);
		enemy.speed = enemy.originalSpeed;
	}
	
	

}
